<?php namespace app\common\service;
use \app\common\model\LitestoreOrderAddress as LitestoreOrderAddressModel;
use think\Loader;

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/3/8
 * Time: 16:24
 */
class LitestoreOrderAddress extends Base {
        public function __construct()
       {
            $LitestoreOrderAddressModel  = new LitestoreOrderAddressModel();
            $this->model = $LitestoreOrderAddressModel;
        }
        public function createAddress($map,$data){
            $validate =  Loader::validate('LitestoreOrderAddress');
            if(!$validate->check($data)){
                $datas = json_encode((object)null);
                return ['code'=>3,'msg'=>$validate->getError(),'data'=>$datas];
            }
            $model = $this->model;
            $res = $model->where($map)->find();
            if($res){
                return ['code'=>2,'msg'=>'已经存在该地址,请换一个地址','data'=>$res];
            }
            $data['createtime']=time();
            $_datas = $model->insertGetId($data);
            if($_datas){
                $data['id']=$_datas;
                return ['code'=>1,'msg'=>'新增地址成功过','data'=>$data];
            }
        }
}